package com.yk.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.prize.domain.Prize;
import com.yk.prize.service.IPrizeService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 奖项Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/prize/prize")
public class PrizeController extends BaseController
{
    private String prefix = "prize/prize";

    @Autowired
    private IPrizeService prizeService;

    @RequiresPermissions("prize:prize:view")
    @GetMapping()
    public String prize()
    {
        return prefix + "/prize";
    }

    /**
     * 查询奖项列表
     */
    @RequiresPermissions("prize:prize:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Prize prize)
    {
        startPage();
        List<Prize> list = prizeService.selectPrizeList(prize);
        return getDataTable(list);
    }

    /**
     * 导出奖项列表
     */
    @RequiresPermissions("prize:prize:export")
    @Log(title = "奖项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Prize prize)
    {
        List<Prize> list = prizeService.selectPrizeList(prize);
        ExcelUtil<Prize> util = new ExcelUtil<Prize>(Prize.class);
        return util.exportExcel(list, "奖项数据");
    }

    /**
     * 新增奖项
     */
    @RequiresPermissions("prize:prize:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存奖项
     */
    @RequiresPermissions("prize:prize:add")
    @Log(title = "奖项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Prize prize)
    {
        return toAjax(prizeService.insertPrize(prize));
    }

    /**
     * 修改奖项
     */
    @RequiresPermissions("prize:prize:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Prize prize = prizeService.selectPrizeById(id);
        mmap.put("prize", prize);
        return prefix + "/edit";
    }

    /**
     * 修改保存奖项
     */
    @RequiresPermissions("prize:prize:edit")
    @Log(title = "奖项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Prize prize)
    {
        return toAjax(prizeService.updatePrize(prize));
    }

    /**
     * 删除奖项
     */
    @RequiresPermissions("prize:prize:remove")
    @Log(title = "奖项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(prizeService.deletePrizeByIds(ids));
    }
}
